unit uXMLUtils;

interface

uses
  
  XMLIntf,
  msxmldom,
  msxml,
  
  uParsing,
  SysUtils;

procedure AddNode(AParentNode: IXMLNode; const ANodeName, ANodeValue: string);
procedure AddParamStrToNode(ANode: IXMLNode; const AParamString: string; const APairDelim: string = '|'; const AParamDelim: string = '=');
function NodeValueAsString(ANode: IXMLDOMNode): string;
function NodeValueAsFloat(ANode: IXMLDOMNode): Double;
function NodeValueAsInteger(ANode: IXMLDOMNode): Integer;

implementation

procedure AddNode(AParentNode: IXMLNode; const ANodeName, ANodeValue: string);
begin
  AParentNode.AddChild(ANodeName);
  AParentNode.ChildValues[ANodeName] := ANodeValue;
end;

procedure AddParamStrToNode(ANode: IXMLNode; const AParamString: string; const APairDelim: string = '|'; const AParamDelim: string = '=');
var
  i: Integer;
  pair: string;
begin
  for i := 1 to CountPos(APairDelim, AParamString) do
  begin
    pair := GetParamByNumber(i, AParamString, APairDelim);
    ANode.AddChild(GetBefore(AParamDelim, pair)).Text := GetAfter(AParamDelim, pair); 
  end;
end;

function NodeValueAsString(ANode: IXMLDOMNode): string;
begin
  if ANode <> nil then Result := ANode.text
  else Result := '';
end;

function NodeValueAsFloat(ANode: IXMLDOMNode): Double;
begin
  DecimalSeparator := '.';
  if ANode <> nil then Result := StrToFloat(ANode.Text)
  else Result := 0;
end;

function NodeValueAsInteger(ANode: IXMLDOMNode): Integer;
begin
  if ANode <> nil then Result := StrToInt(ANode.Text)
  else Result := 0;
end;

end.
